//    Openbravo POS is a point of sales application designed for touch screens.
//    Copyright (S) 2008-2009 Openbravo, S.L.
//    http://www.openbravo.com/product/pos
//
//    This file is part of Openbravo POS.
//
//    Openbravo POS is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    Openbravo POS is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with Openbravo POS.  If not, see <http://www.gnu.org/licenses/>.

package com.openbravo.data.loader.dialect.Oracle;

import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.dialect.AbstractDBDialect;
import com.openbravo.data.loader.dialect.AbstractDDLFactory;
import com.openbravo.data.loader.sentence.SentenceFind;
import com.openbravo.data.loader.serialize.serializer.read.SerializerReadInteger;
import com.openbravo.data.loader.sentence.StaticSentence;
import com.openbravo.data.loader.dialect.SessionDialect;

/**
 * @author adrianromero
 */
public class OracleDBDialect extends AbstractDBDialect {

    public String TRUE() {
        return "1";
    }

    public String FALSE() {
        return "0";
    }

    public String INTEGER_NULL() {
        return "CAST(NULL AS INTEGER)";
    }

    public String CHAR_NULL() {
        return "CAST(NULL AS CHAR)";
    }

    public String getName() {
        return "Oracle";
    }

    public SentenceFind getSequenceSentence(I_Session s, String sequence) {
        return new StaticSentence(s, "SELECT " + sequence + ".NEXTVAL FROM DUAL", null, SerializerReadInteger.INSTANCE);
    }

    @Override
    public AbstractDDLFactory createDDLFactory() {
        return new OracleDDLFactory(this);
    }

    /**

     public String getLimitString(String sql, int offset, String offsetPlaceholder, int limit, String limitPlaceholder) {
     sql = sql.trim();
     boolean isForUpdate = false;
     if (sql.toLowerCase().endsWith(" for update")) {
     sql = sql.substring(0, sql.length() - 11);
     isForUpdate = true;
     }

     StringBuffer pagingSelect = new StringBuffer(sql.length() + 100);
     if (offset > 0) {
     pagingSelect.append("select * from ( dsl row_.*, rownum rownum_ from ( ");
     } else {
     pagingSelect.append("select * from ( ");
     }
     pagingSelect.append(sql);
     if (offset > 0) {
     //			int end = offset+limit;
     String endString = offsetPlaceholder + "+" + limitPlaceholder;
     pagingSelect.append(" ) row_ ) where rownum_ <= " + endString + " and rownum_ > " + offsetPlaceholder);
     } else {
     pagingSelect.append(" ) where rownum <= " + limitPlaceholder);
     }

     if (isForUpdate) {
     pagingSelect.append(" for update");
     }

     return pagingSelect.toString();
     }
     */
}